const { resolve } = require("path");
const HtmlWebapckPlugins = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");

module.exports = {
  entry: { main: "./src/main.js", index: "./src/js/index.js" },
  output: {
    filename: "[name].js",
    path: resolve(__dirname, "dist"),
    library: "browser-table-print",
    libraryTarget: "umd",
    umdNamedDefine: true,
  },
  module: {
    rules: [
      {
        test: /\.(css|less)$/,
        use: [
          //插件的loader取代style-loader，生成单独的文件
          MiniCssExtractPlugin.loader,
          // 处理css
          "css-loader",
          // 将less文件转为css
          "less-loader",
        ],
      },
    ],
  },
  plugins: [
    new HtmlWebapckPlugins({
      template: "./public/index.html",
      chunks: ["index.js"],
    }),
    new MiniCssExtractPlugin({
      filename: "browser-table-print.css",
    }),
  ],
  devServer: {
    compress: true,
    open: true,
    hot: true,
    port: 3000,
  },
  mode: "production",
  // mode: "development",
};
